<?php

namespace app\api\controller\v1;
use app\common\controller\Api;
use app\common\logic\SearchLogic;
class Search extends Api
{
    protected $authenticate = ['only'=>'ff'];
    
   public function index(){
       $params = paramForm();
       $rule = [
           'type|类型'=>'require',
           'word|关键词'=>'require'
       ];
       
       $this->validate($params,$rule);
    
       $filter = [];
       switch ($params['type']){
           case 'mall':
               
               $logic = new SearchLogic();
               $word = $params['word'];
               $userId = $this->getUserId();
                $sellerId = paramForm('sellerId');//如果没有值就是null
               $lists = $logic->searchMall($word,$userId,$sellerId);
               success($lists);
               
               break;
           case 'info':
               $modelClass = 'app\common\model\Info';
               $filter['title'] = ['like','%'.$params['word'].'%'];
               $field = 'id,title,thumb,hits,create_time';
               break;
           case 'company':
               $modelClass = 'app\common\model\Company';
               $filter['title'] = ['like','%'.$params['word'].'%'];
               $field = 'user_id,company,thumb,hits';
               break;
           case 'club':
               $modelClass = 'app\common\model\Club';
               $filter['title'] = ['like','%'.$params['word'].'%'];
               $field = 'id,title,thumb,hits';
               break;
           default:
               error('类别错误');
               break;
       }
       
       $lists = $modelClass::where($filter)->field($field)->select();
       success($lists);
       
   }
   
   
}
